#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

void handler(int signum) {
    printf("捕捉到信号，程序停止，信号号 %d\n", signum);
    exit(0);
}

int main() {
    int count = 0;
    struct sigaction sa;
    sa.sa_handler = handler;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0;
    sigaction(SIGINT, &sa, NULL);
    while(1) {
        count++;
        printf("你好，程序运行了 %d 秒\n", count);
        sleep(1);
    }
    return 0;
}
